<extend name="Base/mobileCommon"/>

<block name="header">
    <style>
        /*----------------mui.showLoading---------------*/
        .mui-show-loading {
            position: fixed;
            padding: 5px;
            width: 120px;
            min-height: 120px;
            top: 45%;
            left: 50%;
            margin-left: -60px;
            background: rgba(0, 0, 0, 0.6);
            text-align: center;
            border-radius: 5px;
            color: #FFFFFF;
            visibility: hidden;
            margin: 0;
            z-index: 2000;

            -webkit-transition-duration: .2s;
            transition-duration: .2s;
            opacity: 0;
            -webkit-transform: scale(0.9) translate(-50%, -50%);
            transform: scale(0.9) translate(-50%, -50%);
            -webkit-transform-origin: 0 0;
            transform-origin: 0 0;
        }
        .mui-show-loading.loading-visible {
            opacity: 1;
            visibility: visible;
            -webkit-transform: scale(1) translate(-50%, -50%);
            transform: scale(1) translate(-50%, -50%);
        }
        .mui-show-loading .mui-spinner{
            margin-top: 24px;
            width: 36px;
            height: 36px;
        }
        .mui-show-loading .text {
            line-height: 1.6;
            font-family: -apple-system-font,"Helvetica Neue",sans-serif;
            font-size: 14px;
            margin: 10px 0 0;
            color: #fff;
        }

        .mui-show-loading-mask {
            position: fixed;
            z-index: 1000;
            top: 0;
            right: 0;
            left: 0;
            bottom: 0;
        }
        .mui-show-loading-mask-hidden{
            display: none !important;
        }
    </style>
</block>

<block name="body">
    <div style="margin:10px;"><i class="mui-icon mui-icon-location"></i>当前地址：<font id="tip">正在获取地址...</font></div>

    <notempty name="data">

        <volist name="data" id="vo">
            <div class="mui-content">
                <div class="mui-card">
                    <div class="mui-card-header">预约顾客：{$vo.name} <?php if($vo['type'] == "Q"){ ?> （{$vo.level_name}） <?php } ?></div>
                    <!--		<div class="mui-card-header" style="color:#FF0000">
                               <i class="mui-icon mui-icon-phone">
                                  <a href="tel:+8617157448571" data-oid="{$vo.id}" onclick="setXphone('+8617157448571','{$vo.id}',{$worker_mobile})"><font size="5">17157448571</font></a>
                               </i>
                            </div>	 -->
                    <?php if($vo['type'] == "Q"){ ?>
                        <div class="mui-card-header">钟点折扣：{$vo.discount}</div>
                        <div class="mui-card-header">保养折扣：{$vo.by_discount}</div>
                        <div class="mui-card-header">可用余额：{$vo.available_funds} 元</div>
                    <?php } ?>
                    <div class="mui-card-header" style="color:#FF0000">预约时间：{$vo.reserve_time|date="Y-m-d H:i:s",###}</div>
                    <div class="mui-card-content">
                        <div class="mui-card-content-inner">
                            <p>服务项目：
                                <volist name="vo.sever_iteam" id="voo">
                                    <span class="mui-badge mui-badge-primary" style="margin:2px;">{$voo.project_name}</span>
                                </volist>
                            </p>
                            <p>服务工具：
                                <volist name="vo.tools" id="voo">
                                    <span class="mui-badge mui-badge-danger" style="margin:2px;">{$voo.name}</span>
                                </volist>
                            </p>
                            <p>我的同伴：
                                <volist name="vo.partner" id="voo">
                                    <span class="mui-badge mui-badge-success" style="margin:2px;"><?php if($voo['type'] == "Q"){echo "质检";}else if($voo['type'] == "S"){echo "客服";}else if($voo['type'] == "W"){echo "服务";} ?>：{$voo.worker_name}</span>
                                </volist>
                            </p>
                            <p>备注：
                                {$vo.show_mark}
                            </p>
                        </div>
                    </div>
                    <div class="mui-card-header" style="line-height:24px;">
                        地址：{$vo.contacts_address}
                    </div>
                    <!-- 	<div class="mui-card-header" style="line-height:24px;">
                            联系电话：<a href="tel:{$vo.contacts_phone}"><font size="5"><span class="mui-icon mui-icon-phone"></span>{$vo.contacts_phone}</font></a>
                            </div>   -->
                    <?php

                    //通过订单查询绑定关系（未过期的）
                    //$padding = 43200;
                    $curr_time = time();
                    //echo date('Y-m-d H:i:s',$curr_time)."<BR>";
                    $map = array();
                    $map['oid'] = $vo['id'];
                    $map['w_id'] = array("EQ",$vo['worker_id']);
                    $map['express_time'] = array("gt",$curr_time);
                    $dao = M("worker_huawei_records_bing");
                    $r = $dao->where($map)->find();

                    ?>
                    <div class="mui-card-header" style="line-height:24px;">
                        <div>联系电话：</div>
                        <?php if($r){ ?>
                            <i class="mui-icon mui-icon-phone">
                                <a id="{$r['oid']}" href="tel:{$r['relationbum']}" data-oid="{$vo.id}"><font size="5">{$r['relationbum']}</font></a>
                            </i>
                        <?php }else{ ?>
                            <i class="mui-icon mui-icon-phone" id="{$vo.id}">
                                <div  data-oid="{$vo.id}" onclick="setXphone('+8617157448571','{$vo.id}',{$worker_mobile},{$vo.worker_id})" style="float:right; margin-left:10px; margin-top:0px"><font size="5">获取号码</font></div>
                            </i>
                        <?php } ?>
                    </div>
                    <?php if($vo['type'] == "W"){ ?>
                        <div class="mui-card-header" style="line-height:24px;">
                            <?php if($vo['work_status']){ ?>
                                <button type="button" class="daka mui-btn mui-btn-danger" style="width:100%" data-workerId="{$vo.worker_id}" data-oid="{$vo.id}" data-workStatus="{$vo.work_status}" data-groupType ="{$group_type}"   data-url="{:U('ajaxChanageWorkStatus')}">
                                    我 要 下 班
                                </button>
                            <?php }else{ ?>
                                <button type="button" class="daka mui-btn mui-btn-primary" style="width:100%" data-workerId="{$vo.worker_id}" data-oid="{$vo.id}" data-workStatus="{$vo.work_status}" data-groupType ="{$group_type}"   data-url="{:U('ajaxChanageWorkStatus')}">
                                    我 要 上 班
                                </button>
                            <?php } ?>

                            &nbsp; <button type="button" class="shareOrder mui-btn mui-btn-primary" style="width:100%" data-workerId="{$vo.worker_id}" data-oid="{$vo.id}" data-workStatus="{$vo.work_status}" data-groupType ="{$group_type}"   data-url="{:U('ajaxCommnentOrder',array('oid'=>$vo[id]))}">
                                邀请顾客确认订单
                            </button>

                        </div>
                    <?php } ?>


                </div>
                <div>

                </div>
            </div>
        </volist>
        <else/>
        <div class="mui-card">
            <div style="margin:20px;">
                暂无派单。如有疑问，请联系派工专员，联系电话：<a href="tel:67270006">67270006</a>
            </div>
        </div>
    </notempty>
    <!--<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=TqkdL2Gf4ExwvoOwCByulxmi6SOCyCRD"></script> -->
    <script src="__STATIC__/mui/js/jquery.min.js"></script>
    <script src="__STATIC__/mui/js/jweixin-1.0.0.js"></script>
    <script type="text/javascript" src="__STATIC__/mui/js/convertor.js"></script>
    <script type="text/javascript" src="__STATIC__/mui/js/mui.js"></script>
    <script>

        wx.config({
            debug: false,
            appId: '<?php echo $signPackage["appId"];?>',
            timestamp: <?php echo $signPackage["timestamp"];?>,
            nonceStr: '<?php echo $signPackage["nonceStr"];?>',
            signature: '<?php echo $signPackage["signature"];?>',
            jsApiList: [
                'checkJsApi',
                'openLocation',
                'getLocation'
            ]
        });

        wx.ready(function () {

            $(".shareOrder").on('click',function(){

                mui.showLoading("正在发送消息..","div");

                var _this = this;
                var url = $(_this).attr("data-url");
                $.ajax({
                    url: url,
                    type: 'GET',
                    contentType: "application/json",
                    dataType: 'json',
                    success: function(data) {
                        mui.hideLoading();
                        alert(data.msg);
                    }
                })

            })

            $(".daka").on('click',function(){

                var _this = this;

                $("#tip").html("正在重新获取当前地址...");

                mui.showLoading("正在打卡..","div");

                wx.getLocation({

                    success: function (res) {
                        var latitude = res.latitude;
                        var longitude = res.longitude;
                        var speed = res.speed;
                        var accuracy = res.accuracy;

                        var url ="http://api.map.baidu.com/geoconv/v1/?coords="+longitude+","+latitude+"&from=1&to=5&ak=TqkdL2Gf4ExwvoOwCByulxmi6SOCyCRD";
                        $.ajax({
                            url: url,
                            type: 'GET',
                            contentType: "application/json",
                            dataType: 'jsonp',//这里要用jsonp的方式不然会报错
                            success: function(data) {

                                var longitude = data.result[0].x;//经度
                                var latitude  = data.result[0].y;//纬度

                                var url_sub = "http://fl.maicooit.com/index.php?s=/Home/Wx/geocoder/longitude/"+longitude+"/latitude/"+latitude+"/ak/TqkdL2Gf4ExwvoOwCByulxmi6SOCyCRD/action/click";
                                $.ajax({
                                    url: url_sub,
                                    type: 'GET',
                                    contentType: "application/json",
                                    dataType: 'json',
                                    success: function(data) {

                                        data.substr(1,data.length-2);
                                        var jsonObject = eval(data);
                                        var  shortAddress = jsonObject.result.formatted_address;
                                        $("#tip").html(shortAddress);

                                        var url = $(_this).attr("data-url");
                                        var data = {};
                                        data['oid'] =  $(_this).attr("data-oid");
                                        data['worker_id'] = $(_this).attr("data-workerId");
                                        data['work_address'] = shortAddress;
                                        data['group_type'] = $(_this).attr('data-groupType');
                                        data['lat'] = longitude;
                                        data['lng'] = latitude;

                                        $.post(url,data,function(res){
                                            //alert(JSON.stringify(res));
                                            //mui.hideLoading(callback); //callback 为回调函数
                                            if(res.status){
                                                mui.hideLoading();
                                                $(_this).text(res.info);
                                                $(_this).removeClass();
                                                $(_this).addClass(res.class);

                                                //获取打卡列表

                                            }else{
                                                mui.hideLoading();
                                                alert(res.msg);
                                            }

                                        });

                                    }

                                });


                            }
                        });


                    },
                    fail: function (){

                        var url ="{:U('Wx/checkgetLocation')}";
                        $.ajax({
                            url: url,
                            type: 'GET',
                            contentType: "application/json",
                            dataType: 'jsonp',//这里要用jsonp的方式不然会报错
                            success: function(data) {


                            }
                        });

                        mui.hideLoading();
                        alert("请打开定位功能");

                    },
                    complete: function (){

                        var url ="{:U('Wx/checkgetLocationcomplete')}";
                        $.ajax({
                            url: url,
                            type: 'GET',
                            contentType: "application/json",
                            dataType: 'jsonp',//这里要用jsonp的方式不然会报错
                            success: function(data) {


                            }
                        });

                    }

                });


            });

            wx.checkJsApi({
                jsApiList: [
                    'getLocation'
                ],
                success: function (res) {
                    if (res.checkResult.getLocation == false) {
                        alert('你的微信版本太低，不支持微信JS接口，请升级到最新的微信版本！');
                        return;
                    }
                }
            });

            <!--使用getLocation接口获取地理位置坐标-->
            wx.getLocation({
                success: function (res) {
                    var latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
                    var longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。
                    var speed = res.speed; // 速度，以米/每秒计
                    var accuracy = res.accuracy; // 位置精度

                    var url ="http://api.map.baidu.com/geoconv/v1/?coords="+longitude+","+latitude+"&from=1&to=5&ak=TqkdL2Gf4ExwvoOwCByulxmi6SOCyCRD";
                    $.ajax({
                        url: url,
                        type: 'GET',
                        contentType: "application/json",
                        dataType: 'jsonp',//这里要用jsonp的方式不然会报错
                        success: function(data) {

                            var longitude = data.result[0].x;//经度
                            var latitude  = data.result[0].y;//纬度

                            var url_sub = "http://fl.maicooit.com/index.php?s=/Home/Wx/geocoder/longitude/"+longitude+"/latitude/"+latitude+"/ak/TqkdL2Gf4ExwvoOwCByulxmi6SOCyCRD";
                            $.ajax({
                                url: url_sub,
                                type: 'GET',
                                contentType: "application/json",
                                dataType: 'json',
                                success: function(data) {
                                    data.substr(1,data.length-2);
                                    var jsonObject = eval(data);
                                    var  shortAddress = jsonObject.result.formatted_address;
                                    console.log(jsonObject);
                                    $("#tip").html(shortAddress);
                                }

                            });


                        }
                    });


                },
                cancel: function (res) {
                    alert('用户拒绝授权获取地理位置');
                }
            });
        });

        //function setXphone(x,oid,m){

        //var url = "{:U('WxWorker/bangding')}";
        //var data = {};
        //data['param'] = oid+'|'+m;
        //data['a'] = m;
        //alert(JSON.stringify(data));
        //$.post(url,data,function(res){
        //alert("");
        //});

        //}

        function setXphone(x,oid,m,w_id){

            var url = "{:U('WxWorker/bangding')}";
            var data = {};
            data['param'] = oid+'|'+m+'|'+w_id;
            //data['a'] = m;
            //alert(JSON.stringify(data));
            $.post(url,data,function(res){
                //alert(JSON.stringify(res));
                //$("#"+oid).attr("href","tel:"+res.msg.relationNum);
                var html = '<a id="'+oid+'" href="tel:'+res.msg.relationNum+'" data-oid='+oid+'><font size="5">'+res.msg.relationNum+'</font></a>'
                $("#"+oid).html(html)
            });

        }
    </script>

</block>